package com.springboot.controller;

import com.springboot.dto.DoctorViewPatient;
import com.springboot.mapper.DoctorInfoFormMapper;
import com.springboot.model.*;
import com.springboot.service.DoctorViewAppointDetailsService;
import com.springboot.service.PatientMyInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
public class testController {
    @Autowired
    DoctorInfoFormMapper doctorInfoFormMapper;

    @Autowired
    DoctorViewAppointDetailsService doctorViewAppointDetailsService;
    @Autowired
    PatientMyInformService patientMyInformService;


    @CrossOrigin
    @RequestMapping(value = "/test8888")
    @ResponseBody
    public String test8888(HttpServletRequest request) {
        System.out.println("医生查看今日预约详情");
        DoctorViewPatient doctorViewPatient = new DoctorViewPatient();
        doctorViewPatient.setPatientName("张三");
        doctorViewPatient.setPatientTel("123456");
        doctorViewPatient.setOrderDate("2020-12-12");
        doctorViewPatient.setOrderTime("上午");
        ArrayList<DoctorViewPatient> doctorViewPatients = new ArrayList<>();
        doctorViewPatients.add(doctorViewPatient);
        doctorViewPatients.add(doctorViewPatient);
        HttpSession session = request.getSession();
        session.setAttribute("doctorViewPatients",doctorViewPatients);
        return "true";
    }

    @CrossOrigin
    @RequestMapping(value = "/loginone")
    @ResponseBody
    public String loginOne(HttpServletRequest request)  {
        HttpSession session = request.getSession();
        return "true";
    }

    @CrossOrigin
    @RequestMapping(value = "/webLogin")
    @ResponseBody
    public String webLogin(HttpServletRequest request)  {
        String tel = "19909722365";
        System.out.println("WEB正在登录");
        HttpSession session = request.getSession();
        session.setAttribute("username",tel);
        String b = (String)session.getAttribute("username");
        System.out.println("username:"+b);
        System.out.println("登录成功");
        return "true";
    }

    @CrossOrigin
    @RequestMapping(value = "/ordertest")
    @ResponseBody
    public String orderTest(HttpServletRequest request)  {
        Integer bookId = 41;
        try {
            OrderForm orderForm =new OrderForm();
            try {
                orderForm = patientMyInformService.findOrderFormByBookId(bookId);
            }
            catch (Exception e)
            {
                System.out.println("patientMyInformService.findOrderFormByBookId(bookId) 出错");
            }
            String bootTime = orderForm.getBootTime();
            Integer patientId = orderForm.getPatientId();
            Integer doctorId = orderForm.getDoctorId();
            MessageInform messageInform = new MessageInform();
            messageInform.setBookDate(orderForm.getBootDate());
            messageInform.setBookTime(bootTime);
            messageInform.setPatientId(patientId);
            messageInform.setDoctorId(doctorId);
            Integer messageMark = 3;
            messageInform.setMessageMark(messageMark);
            Integer messageId = patientMyInformService.insertMessage(messageInform);
            patientMyInformService.insertAssistantMessageInformByDoctorId(doctorId,messageId);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("PatientOrderRecordController 出错");
            System.out.println("取消预约时，消息发送失败");
        }
        return "true";
    }
}
